<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="/plugins/socket-io/socket.io.js"></script>
<script>
    var webscoket=null;
    if('WebSocket' in window){
        webscoket=io('${socketHost}:8102');
    }else {
        alert("该浏览器不支持websocket");
    }
    webscoket.onopen=function (event) {
        console.log("建立连接")
        webscoket.send("hello");
    }
    webscoket.onclose=function (event) {
        console.log("关闭连接")

    }
    webscoket.onmessage=function (event) {
        console.log("收到消息"+event.data);
    }
    webscoket.onerror=function (event) {
        alert("通信发生错误");
    }
    window.onbeforeunload=function () {
        webscoket.close();
    }
</script>